from langchain_community.document_loaders import TextLoader
from langchain_core.documents import Document
from langchain_text_splitters import RecursiveCharacterTextSplitter


class DocsLoader:

    @classmethod
    def load_docs(cls, file_path: str) -> list[Document]:
        """
        加载文档
        :param file_path:
        :return:
        """

        if file_path is None or file_path == "":
            raise Exception("文件路径不可为空")

        # 创建文件加载器
        docs = TextLoader(file_path=file_path, encoding='utf-8')

        if docs is None:
            raise Exception("文件加载器创建失败")

        # 加载文档
        return docs.load()

